﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ITMAN.AssetMan_FRMs
{
    public partial class FRM_neues_asset : Form
    {
        public FRM_neues_asset()
        {
            InitializeComponent();
        }

        private void FRM_neues_asset_Load(object sender, EventArgs e)
        {
            Klassen.CL_assetman assetman = new Klassen.CL_assetman();
            List<string> lst = assetman.get_asset_properties();
            DGV_neues_asset.ColumnCount = lst.Count;
            DGV_neues_asset.Rows.Add();
            for (int i = 0; i < lst.Count; i++)
            {
                DGV_neues_asset.Columns[i].Name = lst[i];
                switch (lst[i])
                {
                    case "Kategorie":
                        DataGridViewComboBoxCell combo_cell = new DataGridViewComboBoxCell();
                        combo_cell.AutoComplete = true;
                        List<string> lst_kat = assetman.get_kategorien();
                        for (int ii = 0; ii < lst_kat.Count; ii++)
                        {
                            combo_cell.Items.Add(lst_kat[ii]);
                        }
                        DGV_neues_asset[i,0] = combo_cell;
                        break;
                    case "Status":
                        DataGridViewComboBoxCell combo_cell_status = new DataGridViewComboBoxCell();
                        combo_cell_status.AutoComplete = true;
                        List<string> lst_status = assetman.get_status();
                        for (int iii = 0; iii < lst_status.Count; iii++)
                        {
                            combo_cell_status.Items.Add(lst_status[iii]);
                        }
                        DGV_neues_asset[i, 0] = combo_cell_status;
                        break;
                    case "Standort":
                        DataGridViewComboBoxCell combo_cell_standort = new DataGridViewComboBoxCell();
                        combo_cell_standort.AutoComplete = true;
                        List<string> lst_standort = assetman.get_standorte();
                        for (int iiii = 0; iiii < lst_standort.Count; iiii++)
                        {
                            combo_cell_standort.Items.Add(lst_standort[iiii]);
                        }
                        DGV_neues_asset[i, 0] = combo_cell_standort;
                        break;
                    case "asset_nr":
                        DGV_neues_asset.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "Ersteller":
                        DGV_neues_asset.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "Erstelldatum":
                        DGV_neues_asset.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "geändert_von":
                        DGV_neues_asset.Rows[0].Cells[i].ReadOnly = true;
                        break;
                    case "letzte_änderung":
                        DGV_neues_asset.Rows[0].Cells[i].ReadOnly = true;
                        break;
                }
            }
       }

        private void BTN_asset_anlegen_Click(object sender, EventArgs e)
        {
            try
            {
                DGV_neues_asset.Rows[0].Selected = true;
                Klassen.CL_assetman assetman = new Klassen.CL_assetman();
                DataGridViewRow row = DGV_neues_asset.SelectedRows[0];
                assetman.insert_new_asset(row);
                DGV_neues_asset.Rows.Clear();
                MessageBox.Show("Asset wurde erfolgreich angelegt");
                this.Close();
            }
            catch (SystemException ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
    }
}
